<template>
  <div class="easyd-weixin-Box">
     <div class="agentInfomationLogBox">
         <img src="static/images/haoxiaozhang.jpg" />
     </div>
     <div class="agentInfomationTitleBox"></div>
     <div class="agentInfomationInputBox">
         <div class="agentInfomationInputItem">
             <input type="text" v-model="addSellForm.name" placeholder="请输入姓名" />
         </div>
         <div class="agentInfomationInputItem">
             <input type="text" v-model="addSellForm.phone" placeholder="请输入电话" />
         </div>
     </div>
     <div class="agentInfomationInputSubmitBox">
         <div class="agentInfomationInputSubmit" @click="submitAction" v-if="$route.query.type == 'zhuguan'">加入成为主管</div>
         <div class="agentInfomationInputSubmit" @click="submitAction" v-else>加入成为销售</div>
     </div>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
    data(){
        return {
            
        }
    },
    computed: {
        ...mapState({
            addSellForm  : state => state.UserModule.sellAddData
        })
    },
    mounted(){
    	
    	if(this.$route.query.type == 'zhuguan'){
    		document.title = '主管员录入';
    	}

    },
    methods : {
        submitAction(){

            if(this.$common.vEmpty(this.addSellForm.name)){
                this.$easyUtil.errorToast(this,'名字不能为空');  
                return; 
            }

            if(!this.$common.vChinese(this.addSellForm.name)){
                this.$easyUtil.errorToast(this,'名字必须为中文');  
                return;
            }

            if(!this.$common.vPhone(this.addSellForm.phone)){
                this.$easyUtil.errorToast(this,'电话格式不正确');  
                return; 
            }

            //判断是否为平台管理人员
            if(this.$userData.getOsid() == '1'){

                var params = {
                    os_id    : this.$userData.getOsid(),
                    os_name  : this.addSellForm.name,
                    os_phone : this.addSellForm.phone
                }

                this.$easyUtil.startLoading(this)
                this.$http.postHttp(this.$API.agentAdd,params,(rs)=>{

                    this.$easyUtil.endLoading(this)
                    this.$easyUtil.successToast(this, '代理商录入成功');
                    this.$store.commit('UserModule/clearSellAddData');

                })

            }else{

                var params = {
                    os_id    : this.$userData.getOsid(),
                    os_type  : this.$userData.getOsType(),
                    u_name  : this.addSellForm.name,
                    u_phone : this.addSellForm.phone
                }
                
                if(this.$route.query.type == 'zhuguan'){
                	params.u_leader = '0';
                	params.u_is_manager = '1';
                	params.os_type = '3';
                }else if(this.$route.query.type == 'xiaoshou'){
                	params.u_leader = this.$userData.getUID();
                	params.u_is_manager = '0';
                	params.os_type = '3';
                }
                console.log(params)
//              return;

                this.$easyUtil.startLoading(this)
                this.$http.postHttp(this.$API.addSales,params,(rs)=>{

                        this.$easyUtil.endLoading(this)
                        
									    	if(this.$route.query.type == 'zhuguan'){
								    			this.$easyUtil.successToast(this, '主管录入成功');
									    	}else{
									    		this.$easyUtil.successToast(this, '销售录入成功');
									    	}
									    	
                        this.$store.commit('UserModule/clearSellAddData');
                        history.go(-1);

                })

            }

            
            
        }
    }
}
</script>

<style lang="stylus" scoped>
@import '~PUBLIC_CSS'
.agentInfomationLogBox {
    width 100%
    height 150px
    text-align center
    margin-top 80px

    img {
        width 150px
        height 150px
        border-radius 5px

    }
}

.agentInfomationTitleBox {
    width 100%
    height 40px
    text-align center
    margin-top 30px
    font-weight 500
    color #666
    letter-spacing 2px
}

.agentInfomationInputBox {
    width 100%
    height auto
    margin-top 10px
    padding-left 15px
    padding-right 15px
    box-sizing border-box

    .agentInfomationInputItem {
        width 100%
        height 45px;
        background #fff
        border-radius 5px    
        margin-bottom 15px
        overflow hidden
        position relative
        border 1px solid #eee

        input {
            width 100%
            height 100%
            padding 15px
            overflow hidden
            border none
            -webkit-appearance: none;
            box-sizing border-box
            outline none
        }
    }
}

.agentInfomationInputSubmitBox {
    width 100%
    height 45px
    padding-left 15px
    box-sizing border-box
    padding-right 15px
    margin-top 30px

    .agentInfomationInputSubmit {
        width 100%
        height 45px
        text-align center
        line-height 45px
        border 1px solid #f0f0f0
        border-radius 5px
        color #fff
        letter-spacing 2px
        background: #FAD236
    }
}

.agentInfomationBottom {
    position absolute
    bottom 0px
    width 100%
    text-align center
    height 40px
    line-height 40px
    font-size 12px
    color #fff
}
</style>